package com.lkd.shoppingcart.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lkd.shoppingcart.entity.OrdersView;
import com.lkd.shoppingcart.service.OrderService;
import com.lkd.shoppingcart.service.impl.OrderServiceImpl;

@WebServlet("/admin/orderServlet")
public class AdminOrderServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;
	private OrderService orderService = new OrderServiceImpl();
	
	/**
	 * 发货
	 * @param req
	 * @param resp
	 * @throws IOException
	 */
	protected void sendOrder(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String orderId = req.getParameter("orderId");
		orderService.updateStatusById(orderId, 1);
		resp.sendRedirect(req.getContextPath()+"/admin/orderServlet?action=showOrder");
	}
	
	/**
	 * 全部发货
	 * @param req
	 * @param resp
	 * @throws IOException
	 */
	protected void sendAllOrders(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		orderService.updateStatus(0, 1);
		resp.sendRedirect(req.getContextPath()+"/admin/orderServlet?action=showOrder");
	}
	
	/**
	 * 获取订单信息
	 * @param req
	 * @param resp
	 * @throws IOException
	 */
	protected void showOrder(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		List<OrdersView> ordersViewList = orderService.queryAll();
		req.getSession().setAttribute("ordersViewList", ordersViewList);
		resp.sendRedirect(req.getContextPath()+"/pages/admin/order_manager.jsp");
	}
	
}
